#!/usr/bin/env python
#-*- coding: UTF-8 -*- 

import sys
import mysql.connector
from mysql.connector import errorcode
reload(sys)
sys.setdefaultencoding("utf8")

config = {
			"user":"zyl",
			"password":"zyl",
			"host":"192.168.131.62",
			"database":"zdc",
			"charset":"utf8",
		}

#cnx = mysql.connector.connect(user="zyl",password="zyl",host="192.168.131.62",database="zdc",charset="utf8")
cnx = mysql.connector.connect(**config)

cursor = cnx.cursor()
cursor.execute("select list_tineng.id,list_tineng.name,sum(list_tineng.num),staff.department from staff,list_tineng where list_tineng.date > staff.k_date AND staff.id = list_tineng.id and staff.status = '在职' group by list_tineng.id having sum(list_tineng.num) > 1000 order by staff.id;")
result = cursor.fetchall()
x = len(result)

f =file("get-1k.txt","w")
for i in range(x):
	print("%d,%s,%d,%s" %(result[i]))
	f.write("%d,%s,%d,%s\n" %(result[i]))


f.close()
cursor.close()
cnx.close()
